// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import "component/"

Rectangle{
    id: _root
    width: 480
    height: 480
    color: "#111111"

    property int score: 0
    property int loopCount: 0
    property int qbCount: 0

    signal exit

    function exec(index){
        switch(index){
        case 0:
            var url = "https://twitter.com/share?hashtags=spaceqb&text="
                    + loopCount + "回時をめぐって" + qbCount + "匹の営業マンをしとめました。(SCORE:" + score + ")"
                    + "&url=http://relog.xii.jp/archives/2012/02/qt_quickspace_i.html";
            Qt.openUrlExternally(url);
            _list.currentIndex = 1;
            break;
        case 1:
            exit();
            _list.currentIndex = 0;
            break;
        default:
            break;
        }
        //
    }

    function pressed(key){
        switch(key){
        case Qt.Key_Left:
        case Qt.Key_Up:
            if(_list.currentIndex > 0){
                _list.currentIndex--;
            }
            break;
        case Qt.Key_Right:
        case Qt.Key_Down:
            if(_list.currentIndex < (_list.count - 1)){
                _list.currentIndex++;
            }
            break;

        case Qt.Key_Enter:
        case Qt.Key_Return:
        case Qt.Key_Space:
            exec(_list.currentIndex);
            break;
        default:
            break;
        }
        //console.debug("key");
    }
    function released(key){

    }

    Keys.onPressed: {
        pressed(event.key);
    }

    Image{
        anchors.margins: 30
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        source: "./images/gameover_gs.png"
    }

    Column{
        anchors.centerIn: parent
        spacing: 60

        Image{
            y: 30
            anchors.horizontalCenter: parent.horizontalCenter
            source: "./images/gameover_title.png"
        }

        ListView{
            id: _list
            interactive: false
            anchors.horizontalCenter: parent.horizontalCenter
            width: 300
            height: 30
            clip: true
            orientation: ListView.Horizontal

            highlight: HighlightRect{
                list: _list
            }
            highlightFollowsCurrentItem: true
            highlightMoveDuration: 200

            model: _model
            delegate: Item{
                width: 150
                height: 30
                Image{
                    anchors.centerIn: parent
                    source: _message
                }
                MouseArea{
                    anchors.fill: parent
                    onClicked: {
                        exec(index);
                    }
                }
            }
        }
    }

    ListModel{
        id: _model
        ListElement{
            //つぶやく
            _message: "./images/gameover_list_1.png"
        }
        ListElement{
            //やりなおす
            _message: "./images/gameover_list_2.png"
        }
    }

}
